#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFileDialog>
#include <QImageReader>
#include <QLineEdit>
#include <QMessageBox>
#include <QButtonGroup>
#include <QStandardItemModel>
#include <QSqlTableModel>
#include <QSqlQuery>
#include <QSqlError>
#include <QTime>
#include <QLabel>
#include <QWidget>
#include <QTextEdit>
#include <QTimer>
#include <ctime>

#include "database.hpp"

#if defined(__linux__)
#define mysleep(nInterval) sleep(nInterval);
#else
#include <windows.h>
#define mysleep(nInterval) Sleep(nInterval);
#endif

#include <QDebug>
#include <QGroupBox>
#include <QSystemTrayIcon>
#define __print(format, ...)                        \
    do                                              \
    {                                               \
        char LOG[1024] = {0};                       \
        snprintf(LOG, 1024, format, ##__VA_ARGS__); \
        ui_showbox(LOG);                            \
        qDebug("%s", LOG);                          \
    } while (0)



namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QMenu *popMenu; // 菜单
    QAction *actionStatus;
    QAction *actionUpdateInfo;
    QAction *actionDelInfo;
    QStandardItemModel *model;
    QStandardItemModel *m_dataModel;
    QTextEdit *m_lb = nullptr;

    // 数据库句柄
    STU_DATA up_data;
    int g_h;

    bool db_updateByFid(STU_DATA *user);
    void ui_TableView_GetData(STU_DATA *user);

    /// 工具栏/////////////////////////////////////////////////
public:

    void tableViewShowFrom();
    bool deleteData(QString tabname, int id, bool msg);
public slots:
    /// 透明移动窗体///////////////////////////////////////////
    void tabchange(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);

private:
    QPoint m_pos;
    bool m_mousepressed;
    bool m_nocheck = false;
    void SeeThroughWindow(QGroupBox *gui);

protected:
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);
    void mousePressEvent(QMouseEvent *envent);
    void mouseReleaseEvent(QMouseEvent *envent);
    void mouseMoveEvent(QMouseEvent *envent);
    void mouseDoubleClickEvent(QMouseEvent *e);
    ///

private slots:
    void slotContextMenu(QPoint pos);
    void actionDelInfo_triggered();
    void actionUpdateInfo_triggered();
    void actionStatus_triggered();

private slots:
    void on_pushButton_done_clicked();
    void on_lineEdit_editingFinished();
    void on_lineEdit_textChanged(const QString &arg1);

    void on_tableView_doubleClicked(const QModelIndex &index);

    void on_pushButton_new_clicked();

    void on_tableView_clicked(const QModelIndex &index);

    void on_pushButton_week_clicked();

    void on_pushButton_clicked();

    void on_checkBox_clicked(bool checked);

private:
    // db
    bool db_create(QSqlDatabase &db, const char *dbname);
    bool db_insert(STU_DATA *user);
    bool db_deleteByUid(QString tabname, int id, bool msg);
    bool db_selectByUid(int uid, char *name, char *icnum);
    void db_read(int start, int stop, QStringList &comm);
    // TableView
    void ui_TableView_Init();
    bool ui_TableView_Show();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
